package com.web.gatewayservice.filter;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;

import java.util.concurrent.Exchanger;

/**
 * @author lenovo
 * @Description
 * @Date2025/4/21 下午3:55
 */
@Component
public class HelloGatewayFilterFactory extends AbstractGatewayFilterFactory<HelloGatewayFilterFactory.Config> {

    public HelloGatewayFilterFactory() {
        //传入参数类的类型
        super(Config.class);
    }

    @Override
    public GatewayFilter apply(Config config) {
        //使用lambda表达式实现GateFilter接口，并返回
        return (exchange,chain) ->{
            System.out.println("hello!------>"+config.getNickname());
            return chain.filter(exchange);
        };
    }

    public static class Config{
        private String nickname;

        public String getNickname() {
            return nickname;
        }

        public void setNickname(String nickname) {
            this.nickname = nickname;
        }
    }
}
